package com.feng.Controller;

import com.feng.Exception.SystemException;
import com.feng.domain.ResponseResult;
import com.feng.domain.entity.User;
import com.feng.domain.enums.AppHttpCodeEnum;
import com.feng.service.BlogLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BlogLoginController {
    @Autowired
    private BlogLoginService blogloginService;
    @PostMapping("/login")
    public ResponseResult login(@RequestBody User user){
        String userName = user.getUserName();
        if(!StringUtils.hasText(userName)){
            //提示 必须要传用户名
            throw new SystemException(AppHttpCodeEnum.REQUIRE_USERNAME);
        }
        return blogloginService.login(user);
    }
    @PostMapping("/logout")
    public  ResponseResult logout(){
      return blogloginService.logout();
    }
    //重置密码接口
    @PostMapping("/fogetpassword")
    public ResponseResult faget(@RequestBody User user){
        String phone=user.getEmail();
        String password=user.getPassword();
        String code=user.getCode();
        return blogloginService.faget(phone,password,code);
    }
}
